package com.eastfair.common.exceptioncode;

import com.eastfair.annotation.base.LanguageTypeEnum;
import com.eastfair.core.context.ContextUtil;
import com.eastfair.core.exception.code.BaseExceptionCode;

/**
 * 公共服务系统异常code定义
 * AABBBCCC   AA(19)  系统编号   BBB 模块    CCC 具体异常
 * 订单：001
 */
public enum CommonServiceExceptionCode implements BaseExceptionCode {

    ;

    private final int code;
    //中文消息
    private String msg;
    //英文消息
    private String enMsg;

    CommonServiceExceptionCode(int code, String msg, String enMsg) {
        this.code = code;
        this.msg = msg;
        this.enMsg = enMsg;
    }

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        //中英文切换
        if(LanguageTypeEnum.CN.name().equals(ContextUtil.getLanguageType())){
            //中文
            return msg;
        }else if(LanguageTypeEnum.EN.name().equals(ContextUtil.getLanguageType())){
            //英文
            return enMsg;
        }
        return msg;
    }


    public CommonServiceExceptionCode build(String msg, Object... param) {
        this.msg = String.format(msg, param);
        return this;
    }

    public CommonServiceExceptionCode param(Object... param) {
        msg = String.format(msg, param);
        return this;
    }


}
